#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# Copyright 2011 Nexenta Systems, Inc. All rights reserved.
# Copyright 2016 Toomas Soome <tsoome@me.com>
# Copyright (c) 2018, Joyent, Inc.
# Copyright 2022 Garrett D'Amore
#

#PROG=		rdate ruptime rwho whois
PROG=		rdate ruptime rwho
#SUIDPROG=	rcp rlogin
#ALL=		$(PROG) $(SUIDPROG)
ALL=		$(PROG)
SRCS=		$(ALL:%=%.c)
#KCMDPROGS=	rcp rlogin

SUBDIRS=	dns-sd netstat
SUBDIRS +=	ping traceroute
#MSGSUBDIRS=

include ../../Makefile.cmd
include ../../Makefile.cmd.64
include ../Makefile.cmd-inet

COMMONOBJS=	kcmd.o
COMMONPOFILES=	$(COMMONOBJS:.o=.po)
COMMONSRCS=	$(CMDINETCOMMONDIR)/$(COMMONOBJS:.o=.c)

#POFILES=	rlogin.po rcp.po $(COMMONPOFILES)
POFILES=	$(COMMONPOFILES)
POFILE=		usr.bin.po

CLOBBERFILES +=	$(ALL)
CLEANFILES +=	kcmd.o rcp.o rlogin.o

all:=		TARGET= all
install:=	TARGET= install
clean:=		TARGET= clean
clobber:=	TARGET= clobber
lint:=		TARGET= lint
_msg:=		TARGET= _msg

ROOTSUIDPROG=	$(SUIDPROG:%=$(ROOTBIN)/%)
$(ROOTSUIDPROG)	:=	FILEMODE=	04555

CPPFLAGS +=	-DSYSV -DSTRNET -DBSD_COMP -I$(CMDINETCOMMONDIR)
CERRWARN +=	-_gcc=-Wno-parentheses
CERRWARN +=	$(CNOWARN_UNINIT)
CERRWARN +=	-_gcc=-Wno-unused-function

ruptime :=     SMOFF += leaks

# Eventually just plain CFLAGS should be += -v, but not until all in
# PROGS are lint clean.
$(LINTCLEAN)	:=	CFLAGS += $(CCVERBOSE)

#rcp lint-rcp :=		LDLIBS += -lsocket -lsec -lsendfile
rdate lint-rdate:=	LDLIBS +=
#rlogin lint-rlogin :=	LDLIBS += -lnsl -lsocket
#whois lint-whois :=	LDLIBS += -lsocket

#include  $(SRC)/lib/gss_mechs/mech_krb5/Makefile.mech_krb5
#$(KCMDPROGS)	:=	LDLIBS += -lnsl -lmech_krb5
#$(KCMDPROGS)	:=	LDFLAGS += $(ZIGNORE) $(KRUNPATH64) \
#				-L$(ROOT)$(KLIBDIR_DO) \
#				-L$(ROOT)$(KLIBDIR_GL)
#KCMDLINTS=	$(KCMDPROGS:%=lint-%)

#$(COMMONPOFILES) \
#rlogin.po rcp.po \
#$(KCMDPROGS) \
#$(KCMDLINTS)	:=	CPPFLAGS += -DKERBEROS \
#			-I$(CMDINETCOMMONDIR) \
#			-I$(SRC)/lib/gss_mechs/mech_krb5 \
#			-I$(SRC)/uts/common/gssapi/mechs/krb5/include \
#			-I$(SRC)/lib/gss_mechs/mech_krb5/include \
#			-I$(SRC)/lib/gss_mechs/mech_krb5/include/krb5

# "-erroff=E_NAME_USED_NOT_DEF2" and "-erroff=E_NAME_DEF_NOT_USED2"
# are required because lint problems in the Kerberos 5 framework.
#$(KCMDLINTS)	:=	LINTFLAGS += -lnsl \
#			-erroff=E_NAME_USED_NOT_DEF2 \
#			-erroff=E_NAME_DEF_NOT_USED2

# Extra source files to lint with
LINTXTRA=
$(KCMDLINTS)	:=	LINTXTRA += $(COMMONSRCS)

#ROOTSUNWRCP=	$(ROOT)/usr/lib/sunw,rcp

.KEEP_STATE:

all: $(ALL) $(SUBDIRS)

#install: all .WAIT $(ROOTPROG) $(ROOTSUIDPROG) \
#	$(SUBDIRS)
install: all .WAIT $(ROOTPROG) \
	$(SUBDIRS)

# Messaging - copy $POFILES to $POFILE to work with the parent directory
# Makefile's '_msg' target.
#
_msg: $(MSGSUBDIRS) $(POFILES)
	$(RM) $(POFILE)
	$(CAT) $(POFILES)	> $(POFILE)

$(COMMONPOFILES): $(COMMONSRCS)
	$(COMPILE.cpp) $(COMMONSRCS) > $(@:.po=.c).i
	$(XGETTEXT) $(XGETFLAGS) $(XGETLANGC) $(@:.po=.c).i
	$(RM) $@
	sed "/^domain/d" < messages.po  > $@
	$(RM) messages.po $(@:.po=.c).i

$(COMMONOBJS): $(COMMONSRCS)
	$(COMPILE.c) $(COMMONSRCS)

$(SUBDIRS): FRC
	@cd $@; pwd; $(MAKE) $(TARGET)

FRC:

clean: $(SUBDIRS) clean_local
clean_local:
	$(RM) $(CLEANFILES)

clobber: $(SUBDIRS) clobber_local
clobber_local: clean_local
	$(RM) $(CLOBBERFILES)

LINTLOCALS=	$(LINTCLEAN:%.c=lint-%)

lint:	$(LINTSUBDIRS) $(LINTLOCALS)

$(LINTLOCALS):
	$(LINT.c) $(@:lint-%=%.c) $(LINTXTRA) $(LDLIBS)
